/*
  ID: nemokin1
  PROG: preface
  LANG: C++
*/

#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <fstream>
 
using namespace std;
 
#define REP(i,n) for(int i=0; i<(n); ++i)
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define FORD(i,a,b) for(int i=(a);i>=b;--i)
#define FOREACH(it,c) for(typeof((c).begin()) it=(c).begin();it!=(c).end();++it)
#define ALL(c) (c).begin(),(c).end()
 
#define debug(x) cerr<< #x << " = " << (x) << "\n";
#define debugv(v) cerr << #v << " = "; FOREACH(it,v) cerr << *it <<","; cerr << "\n";
#define SIZE(a)  (int(a.size()))
 
template<typename T> inline void checkMax(T& a, T b) {if (b>a) a=b;}
template<typename T> inline void checkMin(T& a, T b) {if (b<a) a=b;}
 
typedef long long LL;
typedef vector<int> VI;
typedef vector<string> VS;
typedef long double ld;
const int INF = 1000000000;

int main() {
    freopen("preface.in","r",stdin);freopen("preface.out","w",stdout);
    map<int, string> m;
    m.insert(make_pair(1,"I"));
    m.insert(make_pair(2,"II"));
    m.insert(make_pair(3,"III"));
    m.insert(make_pair(4,"IV"));
    m.insert(make_pair(5,"V"));
    m.insert(make_pair(6,"VI"));
    m.insert(make_pair(7,"VII"));
    m.insert(make_pair(8,"VIII"));
    m.insert(make_pair(9,"IX"));
    m.insert(make_pair(10,"X"));
    m.insert(make_pair(20,"XX"));
    m.insert(make_pair(30,"XXX"));
    m.insert(make_pair(40,"XL"));
    m.insert(make_pair(50,"L"));
    m.insert(make_pair(60,"LX"));
    m.insert(make_pair(70,"LXX"));
    m.insert(make_pair(80,"LXXX"));
    m.insert(make_pair(90,"XC"));
    m.insert(make_pair(100,"C"));
    m.insert(make_pair(200,"CC"));
    m.insert(make_pair(300,"CCC"));
    m.insert(make_pair(400,"CD"));
    m.insert(make_pair(500,"D"));
    m.insert(make_pair(600,"DC"));
    m.insert(make_pair(700,"DCC"));
    m.insert(make_pair(800,"DCCC"));
    m.insert(make_pair(900,"CM"));
    m.insert(make_pair(1000,"M"));
    m.insert(make_pair(2000,"MM"));
    m.insert(make_pair(3000,"MMM"));

    int res[30];
    memset(res,0,sizeof(res));
    
    int N;
    cin >> N;
    for(int i = 1; i <= N; i++){
	string s("");
	int te = i;
	if(te/1000) {s+=m[te/1000*1000];te=te%1000;}
	if(te/100) {s+=m[te/100*100];te=te%100;}
	if(te/10) {s+=m[te/10*10];te=te%10;}
	if(te) s+=m[te];
	for(int j = 0; j < s.size(); j++){
	    res[s[j]-'A']++;
	}
	//cout << s << endl;
    }
    map<char,int> ret;
    for(int i = 0; i < 30; i++){
	ret[i+'A'] = res[i];
    }
    if(ret['I'] != 0) cout << 'I' << " " << ret['I'] << endl;
    if(ret['V'] != 0) cout << 'V' << " " << ret['V'] << endl;
    if(ret['X'] != 0) cout << 'X' << " " << ret['X'] << endl;
    if(ret['L'] != 0) cout << 'L' << " " << ret['L'] << endl;
    if(ret['C'] != 0) cout << 'C' << " " << ret['C'] << endl;
    if(ret['D'] != 0) cout << 'D' << " " << ret['D'] << endl;
    if(ret['M'] != 0) cout << 'M' << " " << ret['M'] << endl;
    exit(0);
}
